package com.lywz.biz.service.food.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lywz.biz.common.dao.CommonDao;
import com.lywz.biz.common.entity.goodfood.SpecialSnack;
import com.lywz.biz.dao.food.SpecialSnackDao;
import com.lywz.biz.service.food.SpecialSnackService;
import com.lywz.core.exception.ExceptionMes;
import com.lywz.core.exception.SSException;
import com.lywz.core.log.LogClerk;

@Service("specialSnackService")
public class SpecialSnackServiceImpl implements SpecialSnackService {

    @Autowired
    private SpecialSnackDao specialSnackDao;

    @Autowired
    private CommonDao commonDao;

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.SpecialSnackService#getSpecialSnackListByPower(int)
     */
    @Override
    public List<SpecialSnack> getSpecialSnackListByPower(int limit) throws SSException {
        try {
            return specialSnackDao.getSpecialSnackListByPower(limit);
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.lywz.biz.service.food.SpecialSnackService#getOneSpecialSnack(java
     * .lang.Integer)
     */
    @Override
    public SpecialSnack getOneSpecialSnack(Integer id) throws SSException {
        try {
            return commonDao.queryById(SpecialSnack.class, id);
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.SpecialSnackService#getAllSpecialSnackListByPower()
     */
    @Override
    public List<SpecialSnack> getAllSpecialSnackListByPower() throws SSException {
        try {
            return specialSnackDao.getAllSpecialSnackListByPower();
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);

        }
    }

    @Override
    public boolean delteOneSpecialSnackById(int specialSnackId) throws SSException {
        try {
            commonDao.delete(getOneSpecialSnack(specialSnackId));
            return true;
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);

        }
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.SpecialSnackService#addOneSnack(com.lywz.biz.common.entity.goodfood.SpecialSnack)
     */
    @Override
    public boolean addOneSnack(SpecialSnack specialSnack) throws SSException {
        try {
            commonDao.insert(specialSnack);
            return true;
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }

    }

    /* (non-Javadoc)
     * @see com.lywz.biz.service.food.SpecialSnackService#updateOneSnack(com.lywz.biz.common.entity.goodfood.SpecialSnack)
     */
    @Override
    public boolean updateOneSnack(SpecialSnack specialSnack) throws SSException {
        try {
            commonDao.update(specialSnack);
            return true;
        } catch (Exception e) {
            LogClerk.sysout.error(e);
            throw SSException.get(ExceptionMes.SYSEXCEPTION);
        }
    }

}
